﻿using FluentNHibernate.Mapping;
using SmallTune.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmallTune.Mappings
{
    public class AlbumMap : ClassMap<Album>
    {
        public AlbumMap()
        {
            Id(x => x.Id);
            Map(x => x.created);
            Map(x => x.lastChanged);
            ///An Artist can have many Albums, and
            ///an Album can belong to many artists
            HasManyToMany(x => x.listOfArtists)
                .Cascade.All()
                .Inverse()
                .Table("AlbumsArtists");
            ///A Genre can belong to many albums,
            ///and many albums can have a genre
            HasManyToMany(x => x.listOfGenres)
                .Cascade.All()
                .Table("AlbumsGenres");
            ///A Song can belong to many albums (think of best ofs, etc...),
            ///and a album can belong to many songs (obviously...)
            HasManyToMany(x => x.listOfSongs)
                .Cascade.All()
                .Table("AlbumsSongs");
            Map(x => x.name);
            Map(x => x.yearOfRelease);
        }
    }
}
